let pageNum = 1;
let pageNumCon = 1;
let totalPage;
$(function () {
    $.ajax({
        url:"/orderVerify/queryOrder",
        type:"post",
        datatype:"json",
        success:function (r) {
            console.log(r)
            if (r!=null) {
                var t = "";
                var i = 1;
                for (let j = 0; j < r.data.length; j++) {
                    let status = "";
                    if (r.data[j].status === "1") {
                        status = "审核中";
                    }
                    t += "<tr>\n" +
                        "          <td>" + (i++) + "</td>\n" +
                        "          <td id='" + r.data[j].orderid + "'>" + r.data[j].orderid + "</td>\n" +
                        "          <td>" + r.data[j].customname + "</td>\n" +
                        "          <td>" + r.data[j].phone + "</td>\n" +
                        "          <td>" + r.data[j].ordertime + "</td>\n" +
                        "          <td>" + r.data[j].totalprice + "</td>\n" +
                        "          <td>" + r.data[j].operatorname + "</td>\n" +
                        "          <td>" + status + "</td>\n" +
                        "          <td>\n" +
                        "          \t<a href=\"javascript:void(0)\" onclick='toCheck(this)' class=\"tablelink\">审核</a>\n" +
                        "          </td>\n" +
                        "        </tr>";
                }
                $(".tablelist tbody").html(t);
                $(".paginList").html("<li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagepre\" onclick=\"prevPage(this)\"></span></a></li><li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagenxt\" onclick=\"nextPage(this)\"></span></a></li>");
                $(".message>i").eq(0).html(r.totalRows);
                $(".message>i").eq(1).html(r.pageNum);
                totalPage = r.totalPage;
            }else {
                $(".tablelist tbody").html("空");
            }
        }
    })
})

function queryOrderByCondition() {
    let orderid = $("input[name='orderid']").val();
    let customname = $("input[name='customname']").val();
    let startTime = $("input[name='startTime']").val();
    let endTime = $("input[name='endTime']").val();
    let minprice = $("input[name='minprice']").val();
    let maxprice = $("input[name='maxprice']").val();

    $.ajax({
            url:"/orderVerify/queryOrder",
        type:"post",
        data:{"orderid":orderid,"customname":customname,"startTime":startTime,"endTime":endTime,"minprice":minprice,"maxprice":maxprice},
        datatype:"json",
        success:function (r) {
            console.log(r)
            if (r!=null) {
                var t = "";
                var i = 1;
                for (let j = 0; j < r.data.length; j++) {
                    let status = "";
                    if (r.data[j].status === "1") {
                        status = "审核中";
                    }
                    t += "<tr>\n" +
                        "          <td>" + (i++) + "</td>\n" +
                        "          <td id='" + r.data[j].orderid + "'>" + r.data[j].orderid + "</td>\n" +
                        "          <td>" + r.data[j].customname + "</td>\n" +
                        "          <td>" + r.data[j].phone + "</td>\n" +
                        "          <td>" + r.data[j].ordertime + "</td>\n" +
                        "          <td>" + r.data[j].totalprice + "</td>\n" +
                        "          <td>" + r.data[j].operatorname + "</td>\n" +
                        "          <td>" + status + "</td>\n" +
                        "          <td>\n" +
                        "          \t<a href=\"javascript:void(0)\" onclick='toCheck(this)' class=\"tablelink\">审核</a>\n" +
                        "          </td>\n" +
                        "        </tr>";
                }
                $(".tablelist tbody").html(t);
                $(".paginList").html("<li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagepre\" onclick=\"prevPage1(this)\"></span></a></li><li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagenxt\" onclick=\"nextPage1(this)\"></span></a></li>");
                $(".message>i").eq(0).html(r.totalRows);
                $(".message>i").eq(1).html(r.pageNum);
                totalPage = r.totalPage;
            }else {
                $(".tablelist tbody").html("空");
            }
        }
    })

}

function toCheck(a){
    let orderid = $(a).parents().siblings("td").eq(1).attr("id");
    $.ajax({
        url:"/orderVerify/putOrderId",
        type:"post",
        data:{"orderid":orderid},
        success:function () {
            location.href="orderExamine.html";
        }
    })

}

function nextPage() {
    if (pageNum<totalPage){
        pageNum++;
    }
    $.ajax({
        url:"/orderVerify/queryOrder",
        type:"post",
        data:{"pageNum":pageNum},
        datatype:"json",
        success:function (r) {
            console.log(r)
            if (r!=null) {
                var t = "";
                var i = 1;
                for (let j = 0; j < r.data.length; j++) {
                    let status = "";
                    if (r.data[j].status === "1") {
                        status = "审核中";
                    }
                    t += "<tr>\n" +
                        "          <td>" + (i++) + "</td>\n" +
                        "          <td id='" + r.data[j].orderid + "'>" + r.data[j].orderid + "</td>\n" +
                        "          <td>" + r.data[j].customname + "</td>\n" +
                        "          <td>" + r.data[j].phone + "</td>\n" +
                        "          <td>" + r.data[j].ordertime + "</td>\n" +
                        "          <td>" + r.data[j].totalprice + "</td>\n" +
                        "          <td>" + r.data[j].operatorname + "</td>\n" +
                        "          <td>" + status + "</td>\n" +
                        "          <td>\n" +
                        "          \t<a href=\"javascript:void(0)\" onclick='toCheck(this)' class=\"tablelink\">审核</a>\n" +
                        "          </td>\n" +
                        "        </tr>";
                }
                $(".tablelist tbody").html(t);
                $(".paginList").html("<li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagepre\" onclick=\"prevPage(this)\"></span></a></li><li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagenxt\" onclick=\"nextPage(this)\"></span></a></li>");
                $(".message>i").eq(0).html(r.totalRows);
                $(".message>i").eq(1).html(r.pageNum);
            }else {
                $(".tablelist tbody").html("空");
            }
        }
    })
}
function prevPage() {
    if (pageNum>1){
        pageNum--;
    }
    $.ajax({
        url:"/orderVerify/queryOrder",
        type:"post",
        data:{"pageNum":pageNum},
        datatype:"json",
        success:function (r) {
            console.log(r)
            if (r!=null) {
                var t = "";
                var i = 1;
                for (let j = 0; j < r.data.length; j++) {
                    let status = "";
                    if (r.data[j].status === "1") {
                        status = "审核中";
                    }
                    t += "<tr>\n" +
                        "          <td>" + (i++) + "</td>\n" +
                        "          <td id='" + r.data[j].orderid + "'>" + r.data[j].orderid + "</td>\n" +
                        "          <td>" + r.data[j].customname + "</td>\n" +
                        "          <td>" + r.data[j].phone + "</td>\n" +
                        "          <td>" + r.data[j].ordertime + "</td>\n" +
                        "          <td>" + r.data[j].totalprice + "</td>\n" +
                        "          <td>" + r.data[j].operatorname + "</td>\n" +
                        "          <td>" + status + "</td>\n" +
                        "          <td>\n" +
                        "          \t<a href=\"javascript:void(0)\" onclick='toCheck(this)' class=\"tablelink\">审核</a>\n" +
                        "          </td>\n" +
                        "        </tr>";
                }
                $(".tablelist tbody").html(t);
                $(".paginList").html("<li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagepre\" onclick=\"prevPage(this)\"></span></a></li><li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagenxt\" onclick=\"nextPage(this)\"></span></a></li>");
                $(".message>i").eq(0).html(r.totalRows);
                $(".message>i").eq(1).html(r.pageNum);
            }else {
                $(".tablelist tbody").html("空");
            }
        }
    })
}
function nextPage1() {
    if (pageNumCon<totalPage){
        pageNumCon++;
    }
    let orderid = $("input[name='orderid']").val();
    let customname = $("input[name='customname']").val();
    let startTime = $("input[name='startTime']").val();
    let endTime = $("input[name='endTime']").val();
    let minprice = $("input[name='minprice']").val();
    let maxprice = $("input[name='maxprice']").val();

    $.ajax({
        url:"/orderVerify/queryOrder",
        type:"post",
        data:{"pageNum":pageNumCon,"orderid":orderid,"customname":customname,"startTime":startTime,"endTime":endTime,"minprice":minprice,"maxprice":maxprice},
        datatype:"json",
        success:function (r) {
            console.log(r)
            if (r!=null) {
                var t = "";
                var i = 1;
                for (let j = 0; j < r.data.length; j++) {
                    let status = "";
                    if (r.data[j].status === "1") {
                        status = "审核中";
                    }
                    t += "<tr>\n" +
                        "          <td>" + (i++) + "</td>\n" +
                        "          <td id='" + r.data[j].orderid + "'>" + r.data[j].orderid + "</td>\n" +
                        "          <td>" + r.data[j].customname + "</td>\n" +
                        "          <td>" + r.data[j].phone + "</td>\n" +
                        "          <td>" + r.data[j].ordertime + "</td>\n" +
                        "          <td>" + r.data[j].totalprice + "</td>\n" +
                        "          <td>" + r.data[j].operatorname + "</td>\n" +
                        "          <td>" + status + "</td>\n" +
                        "          <td>\n" +
                        "          \t<a href=\"javascript:void(0)\" onclick='toCheck(this)' class=\"tablelink\">审核</a>\n" +
                        "          </td>\n" +
                        "        </tr>";
                }
                $(".tablelist tbody").html(t);
                $(".paginList").html("<li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagepre\" onclick=\"prevPage1(this)\"></span></a></li><li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagenxt\" onclick=\"nextPage1(this)\"></span></a></li>");
                $(".message>i").eq(0).html(r.totalRows);
                $(".message>i").eq(1).html(r.pageNum);
            }else {
                $(".tablelist tbody").html("空");
            }
        }
    })

}
function prevPage1() {
    if (pageNumCon>1){
        pageNumCon--;
    }
    let orderid = $("input[name='orderid']").val();
    let customname = $("input[name='customname']").val();
    let startTime = $("input[name='startTime']").val();
    let endTime = $("input[name='endTime']").val();
    let minprice = $("input[name='minprice']").val();
    let maxprice = $("input[name='maxprice']").val();

    $.ajax({
        url:"/orderVerify/queryOrder",
        type:"post",
        data:{"pageNum":pageNumCon,"orderid":orderid,"customname":customname,"startTime":startTime,"endTime":endTime,"minprice":minprice,"maxprice":maxprice},
        datatype:"json",
        success:function (r) {
            console.log(r)
            if (r!=null) {
                var t = "";
                var i = 1;
                for (let j = 0; j < r.data.length; j++) {
                    let status = "";
                    if (r.data[j].status === "1") {
                        status = "审核中";
                    }
                    t += "<tr>\n" +
                        "          <td>" + (i++) + "</td>\n" +
                        "          <td id='" + r.data[j].orderid + "'>" + r.data[j].orderid + "</td>\n" +
                        "          <td>" + r.data[j].customname + "</td>\n" +
                        "          <td>" + r.data[j].phone + "</td>\n" +
                        "          <td>" + r.data[j].ordertime + "</td>\n" +
                        "          <td>" + r.data[j].totalprice + "</td>\n" +
                        "          <td>" + r.data[j].operatorname + "</td>\n" +
                        "          <td>" + status + "</td>\n" +
                        "          <td>\n" +
                        "          \t<a href=\"javascript:void(0)\" onclick='toCheck(this)' class=\"tablelink\">审核</a>\n" +
                        "          </td>\n" +
                        "        </tr>";
                }
                $(".tablelist tbody").html(t);
                $(".paginList").html("<li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagepre\" onclick=\"prevPage1(this)\"></span></a></li><li class=\"paginItem\"><a href=\"javascript:;\"><span class=\"pagenxt\" onclick=\"nextPage1(this)\"></span></a></li>");
                $(".message>i").eq(0).html(r.totalRows);
                $(".message>i").eq(1).html(r.pageNum);
            }else {
                $(".tablelist tbody").html("空");
            }
        }
    })

}